package com.chuanjiabao.wisdom.ui.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.databinding.ActivityCreateSecretInputPwdBinding;
import com.chuanjiabao.wisdom.ui.BaseActivity;
import com.chuanjiabao.wisdom.util.ToastUtil;

public class CreateSecretInputPwdActivity extends BaseActivity {

    ActivityCreateSecretInputPwdBinding binding;
    boolean isShow = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_create_secret_input_pwd);
        binding.setActivity(this);
        initView();
    }

    private void initView() {
        binding.tvModuleOk.setOnClickListener(this);
        binding.tvModuleLook.setOnClickListener(this);
        binding.ivModuleDelete.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivModuleDelete:
                finish();
                break;
            case R.id.tvModuleOk:
                String pwd = binding.etModuleSecretPwd.getText().toString().trim();
                if (TextUtils.isEmpty(pwd)) {
                    ToastUtil.showToast("请输入密码");
                    return;
                }

                if (pwd.length() != 6) {
                    ToastUtil.showToast("密码不能少于六位");
                    return;
                }

                Intent intent = new Intent(
                        CreateSecretInputPwdActivity.this,
                        CreateSecretInputBodyNumActivity.class
                );
                intent.putExtra("module_num", pwd);
                startActivity(intent);
                finish();
                break;
            case R.id.tvModuleLook:
                if (!isShow) {
                    isShow = true;
                    binding.etModuleSecretPwd.setInputType(128);
                } else {
                    isShow = false;
                    binding.etModuleSecretPwd.setInputType(129);
                }
                break;
        }
    }
}
